
class_name CCharConst

extends EventDispatcher

signal UUID_changed(old_value, new_value) 
signal AccountName_changed(old_value, new_value) 
signal AccountID_changed(old_value, new_value) 
signal CharName_changed(old_value, new_value) 
signal CreateTime_changed(old_value, new_value) 
signal RegisterIp_changed(old_value, new_value) 
signal GMPriority_changed(old_value, new_value) 
signal ForbidLoginTime_changed(old_value, new_value) 
signal ForbidLoginReason_changed(old_value, new_value) 
signal ForbidChatTime_changed(old_value, new_value) 
signal ForbidChatReason_changed(old_value, new_value) 
signal DeleteFlag_changed(old_value, new_value) 
signal GasID_changed(old_value, new_value) 
signal CurLang_changed(old_value, new_value) 
signal CurNation_changed(old_value, new_value) 
signal CurPlatform_changed(old_value, new_value) 


var m_tblAlias
var bInited = false
func _init(_uuid)->void:
    self.UUID = _uuid
    self.AccountName = ''
    self.AccountID = 0
    self.CharName = ''
    self.CreateTime = 0	# 创建时间
    self.RegisterIp = ''	# 玩家注册IP
    self.GMPriority = 0	# 权重值
    self.ForbidLoginTime = 0	# 禁止登陆时间
    self.ForbidLoginReason = ''	# 理由
    self.ForbidChatTime = 0	# 禁言时间
    self.ForbidChatReason = ''	# 理由
    self.DeleteFlag = 0	# 删除标记
    self.GasID = 0
    self.CurLang = 0	# 当前语言
    self.CurNation = ''	# 当前国家
    self.CurPlatform = ''	# 当前渠道

    self.m_tblAlias = {
 
    }

func UnPack(_bufferStream):
    self.UUID = _bufferStream.ReadInt64()
    self.AccountName = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_AccountName)
    self.AccountID = _bufferStream.ReadInt64()
    self.CharName = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_CharName)
    self.CreateTime = _bufferStream.ReadInt32()
    self.RegisterIp = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_RegisterIp)
    self.GMPriority = _bufferStream.ReadInt32()
    self.ForbidLoginTime = _bufferStream.ReadUint64()
    self.ForbidLoginReason = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_ForbidLoginReason)
    self.ForbidChatTime = _bufferStream.ReadUint64()
    self.ForbidChatReason = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_ForbidChatReason)
    self.DeleteFlag = _bufferStream.ReadUint8()
    self.GasID = _bufferStream.ReadUint16()
    self.CurLang = _bufferStream.ReadUint16()
    self.CurNation = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_CurNation)
    self.CurPlatform = _bufferStream.ReadString(TableCommonDefine.ECharLen.eCL_CurPlatform)

    self.bInited = true


func GetTableName():
    return 'CharConst'

func CopyFrom(other):
    self.AccountName = other.AccountName
    self.AccountID = other.AccountID
    self.CharName = other.CharName
    self.CreateTime = other.CreateTime
    self.RegisterIp = other.RegisterIp
    self.GMPriority = other.GMPriority
    self.ForbidLoginTime = other.ForbidLoginTime
    self.ForbidLoginReason = other.ForbidLoginReason
    self.ForbidChatTime = other.ForbidChatTime
    self.ForbidChatReason = other.ForbidChatReason
    self.DeleteFlag = other.DeleteFlag
    self.GasID = other.GasID
    self.CurLang = other.CurLang
    self.CurNation = other.CurNation
    self.CurPlatform = other.CurPlatform


func OnDataChanged( fieldName, oldValue, newValue):
    if oldValue == newValue:
        return
    
    self.DispatchEvent(fieldName, [self, oldValue, newValue])
    #  Alias
    if self.m_tblAlias[fieldName] != null:
        for i in range(self.m_tblAlias[fieldName].size()):
            self.DispatchEvent(self.m_tblAlias[fieldName][i], [self, oldValue, newValue])

func UnPackField(_fieldId, _bufferStream, _varLen ):
    if _fieldId < 0 or _fieldId == 0xffff:
        var old = CCharConst.new(self.m_UUID)
        old.CopyFrom( self )
        self.UnPack( _bufferStream )
        self.DispatchEvent("CCharConst", [self, old, self])
        return true

    print("UnPackField error tblName = CharConst, className = CCharConst, _fieldId = ", _fieldId)
    # if _fieldId > Fields_CharConstID.size():
    #     var szLog = 'CCharConst.UnPackField  _fieldId(%d) < 0 or _fieldId(%d) > #Fields_CharConstID(%d)' % [_fieldId, _fieldId,  Fields_CharConstID.size()]
    #     print(szLog)
    #     return false

    # Fields_CharConstID[_fieldId].reader( self, _bufferStream, _varLen)

    return true

func AddField(_fieldId, _bufferStream):
    print( "[TABLEDATA] error AddField", "CCharConst", _fieldId )

    
func DelField(_fieldId ):
    print( "[TABLEDATA] error DelField", "CCharConst", _fieldId )

var UUID:
    set(value):
        var old = self.m_UUID
        self.UUID = _value
        self.UUID_changed.emit(old, _value)

    get:
        return self.UUID


var AccountName:
    set(value):
        var old = self.m_AccountName
        self.AccountName = _value
        self.AccountName_changed.emit(old, _value)

    get:
        return self.AccountName


var AccountID:
    set(value):
        var old = self.m_AccountID
        self.AccountID = _value
        self.AccountID_changed.emit(old, _value)

    get:
        return self.AccountID


var CharName:
    set(value):
        var old = self.m_CharName
        self.CharName = _value
        self.CharName_changed.emit(old, _value)

    get:
        return self.CharName


var CreateTime:
    set(value):
        var old = self.m_CreateTime
        self.CreateTime = _value
        self.CreateTime_changed.emit(old, _value)

    get:
        return self.CreateTime


var RegisterIp:
    set(value):
        var old = self.m_RegisterIp
        self.RegisterIp = _value
        self.RegisterIp_changed.emit(old, _value)

    get:
        return self.RegisterIp


var GMPriority:
    set(value):
        var old = self.m_GMPriority
        self.GMPriority = _value
        self.GMPriority_changed.emit(old, _value)

    get:
        return self.GMPriority


var ForbidLoginTime:
    set(value):
        var old = self.m_ForbidLoginTime
        self.ForbidLoginTime = _value
        self.ForbidLoginTime_changed.emit(old, _value)

    get:
        return self.ForbidLoginTime


var ForbidLoginReason:
    set(value):
        var old = self.m_ForbidLoginReason
        self.ForbidLoginReason = _value
        self.ForbidLoginReason_changed.emit(old, _value)

    get:
        return self.ForbidLoginReason


var ForbidChatTime:
    set(value):
        var old = self.m_ForbidChatTime
        self.ForbidChatTime = _value
        self.ForbidChatTime_changed.emit(old, _value)

    get:
        return self.ForbidChatTime


var ForbidChatReason:
    set(value):
        var old = self.m_ForbidChatReason
        self.ForbidChatReason = _value
        self.ForbidChatReason_changed.emit(old, _value)

    get:
        return self.ForbidChatReason


var DeleteFlag:
    set(value):
        var old = self.m_DeleteFlag
        self.DeleteFlag = _value
        self.DeleteFlag_changed.emit(old, _value)

    get:
        return self.DeleteFlag


var GasID:
    set(value):
        var old = self.m_GasID
        self.GasID = _value
        self.GasID_changed.emit(old, _value)

    get:
        return self.GasID


var CurLang:
    set(value):
        var old = self.m_CurLang
        self.CurLang = _value
        self.CurLang_changed.emit(old, _value)

    get:
        return self.CurLang


var CurNation:
    set(value):
        var old = self.m_CurNation
        self.CurNation = _value
        self.CurNation_changed.emit(old, _value)

    get:
        return self.CurNation


var CurPlatform:
    set(value):
        var old = self.m_CurPlatform
        self.CurPlatform = _value
        self.CurPlatform_changed.emit(old, _value)

    get:
        return self.CurPlatform



